<?php

namespace Frieza\Modules\Position\Controllers;

use Encore\Admin\Grid;
use Encore\Admin\Widgets\Form;
use Encore\Admin\Widgets\Tab;
use Illuminate\Http\Request;


class HomeChannelV5Controller extends BaseController
{
    use BaseTrait;

    public $tabName = '一级列表';
    public $filter_field_pos = false;
    public $filter_field_uid = false;

    public function afterTab(Tab $tab, Request $request)
    {
        $request->input('ext_type', 1);

        $tab->addLink('二级列表', $this->listRoute . "?ext_type=2", $request->input('ext_type', 1) == 2);
    }

    public function extendList(Grid $grid)
    {
        $grid->column('pos', '位置');
        $grid->column('title', '标题');
        $grid->column('pic_url', '图标')->image('', 50);
        $grid->column('single_pic_url', '角标')->image('', 50);
    }

    public function defaultBaseInfo(Request $request)
    {
        $response = parent::defaultBaseInfo($request);

        $response['pos'] = $request->input('pos', 1) == 2 ? 2 : 1;

        return $response;
    }

    public function condition($request)
    {
        $condition = parent::condition($request);

        if (empty($condition['ext_type']) || $condition['ext_type'] != 2) $condition['ext_type'] = 1;

        return $condition;
    }

    public function beforeLinkForm(Form $form)
    {
        $options = [
            '1' => '一级',
            '2' => '二级',
        ];
        $form->radio('base.ext_type', '蜂窝煤类型')->options($options);
        $form->select('base.pos', '位置')->options(array_combine(range(1, 20), range(1, 20)));
        $form->text('base.title', '标题');
        $form->imgUpload('base.pic_id', '图标');
        $form->imgUpload('base.single_pic_id', '角标')->help("角标旨在让用户及时发现频道有了新变动
<br/>
但出于对app整体的考虑，为避免「多个角标同时出现造成视觉混乱，降低角标对用户吸引度」的情况，同一时间段内，仅允许一个角标生效
<br/>
如果在选择生效时间时，发现某一时段不可选，是正常现象");
    }

}
